home *** CD-ROM | disk | FTP | other *** search
- Listing 2 - non-inline member function definitions for a generic queue
- using void * elements and an two-argument iteration function
-
- //
- // genq4.cpp - generic queue of void *
- // with a two-argument iteration function
- //
-
- #include "genq4.h"
-
- void genq::append(void *e)
- {
- cell *p = new cell(e, 0);
- if (first == 0)
- first = p;
- else
- last->next = p;
- last = p;
- }
-
- void genq::
- apply(void f(void *e, void *a), void *args)
- {
- cell *p;
- for (p = first; p != 0; p = p->next)
- f(p->element, args);
- }
-
- int genq::remove(void *&e)
- {
- if (first == 0)
- return 0;
- cell *p = first;
- if ((first = first->next) == 0)
- last = 0;
- e = p->element;
- delete p;
- return 1;
- }
-
-